package com.vinjogames.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;


public class Preferences {

	private static SharedPreferences mPrefs;
	private static SharedPreferences.Editor mEditor;
	public static final String SOUND_KEY = "soundOnOff";
	public static final String MUSIC_KEY = "musicOnOff";
	public static final String VIBRATE_KEY = "vibrateOnOff";
	public static final String LAST_IP_KEY = "lastIPConnection";
	public static final String DEBUG_KEY = "debugOnOff";
	
	public static final boolean SOUND_DEFAULT = true;
	public static final boolean MUSIC_DEFAULT = true;
	public static final boolean VIBRATE_DEFAULT = true;
	public static final String LAST_IP_DEFAULT = "";
	public static final boolean DEBUG_DEFAULT = false; //TODO: turn off, or remove for final release
	
	public static void ToggleSound(){
		if(mPrefs == null){ return;}
		if(mPrefs.contains(SOUND_KEY)){
			mEditor.putBoolean(SOUND_KEY, !getSoundSetting());
			mEditor.commit();
		}
	}
	
	public static void ToggleMusic(){
		if(mPrefs == null){ return;}
		if(mPrefs.contains(MUSIC_KEY)){
			mEditor.putBoolean(MUSIC_KEY, !getMusicSetting());
			mEditor.commit();
		}
	}
	
	public static void ToggleVibrate(){
		if(mPrefs == null){ return;}
		if(mPrefs.contains(VIBRATE_KEY)){
			mEditor.putBoolean(VIBRATE_KEY, !getVibrateSetting());
			mEditor.commit();
		}
	}
	
	public static void ToggleDebug(){
		if(mPrefs == null){ return;}
		if(mPrefs.contains(DEBUG_KEY)){
			mEditor.putBoolean(DEBUG_KEY, !getDebugSetting());
			mEditor.commit();
		}
	}
	
	public static boolean getSoundSetting(){
		return mPrefs.getBoolean(SOUND_KEY, SOUND_DEFAULT);
	}
	
	public static boolean getMusicSetting(){
		return mPrefs.getBoolean(MUSIC_KEY, MUSIC_DEFAULT);
	}
	
	public static boolean getVibrateSetting(){
		return mPrefs.getBoolean(VIBRATE_KEY, VIBRATE_DEFAULT);
	}
	
	public static boolean getDebugSetting(){
		return mPrefs.getBoolean(DEBUG_KEY, DEBUG_DEFAULT);
	}
	
	public static String getLastIP(){
		return mPrefs.getString(LAST_IP_KEY, LAST_IP_DEFAULT);
	}
	
	public static void setLastIP(String ip){
		mEditor.putString(LAST_IP_KEY, ip);
		mEditor.commit();
	}
	
	
	public static void setUpPrefs(Context context){  
		mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
		mEditor = mPrefs.edit();
		
		if(!mPrefs.contains(SOUND_KEY)){
			mEditor.putBoolean(SOUND_KEY, SOUND_DEFAULT);
		}
		if(!mPrefs.contains(MUSIC_KEY)){
			mEditor.putBoolean(MUSIC_KEY, MUSIC_DEFAULT);
		}
		if(!mPrefs.contains(VIBRATE_KEY)){
			mEditor.putBoolean(VIBRATE_KEY, VIBRATE_DEFAULT);
		}
		if(!mPrefs.contains(DEBUG_KEY)){
			mEditor.putBoolean(DEBUG_KEY, DEBUG_DEFAULT);
		}
		
		mEditor.commit();
	}
}
